<template>
  <view class="creation-page">
<!-- 贴边操作按钮 -->
    <view class="side-action-wrapper">
      <!-- 触发按钮 -->
      <view class="trigger-button" @click="toggleActions">
        <text class="trigger-text"></text>
      </view>
      
      <!-- 隐藏的操作按钮组 -->
      <view class="actions-container" :class="{ expanded: isActionsExpanded }">
        <view class="action-button create" @click="switchToCreate">
          <text class="action-text">创建菜谱</text>
        </view>
        
        <view class="action-button edit" @click="switchToEdit">
          <text class="action-text">编辑菜谱</text>
        </view>
      </view>
    </view>
    
    <!-- 主要内容区 -->
    <view class="content-container">
      <!-- 封面图片上传 -->
      <view class="cover-upload">
        <image :src="recipeForm.cover_image || '/static/images/02.jpg'" mode="aspectFill" class="cover-image" @click="uploadCover"></image>
        <view class="upload-tip">点击上传封面图片</view>
      </view>

      <!-- 基本信息表单 -->
      <view class="form-section">
        <view class="form-item">
          <text class="label">菜谱标题 *</text>
          <input type="text" v-model="recipeForm.title" placeholder="请输入菜谱标题" class="input" placeholder-style="color: #999;" />
        </view>

        <view class="form-item">
          <text class="label">描述</text>
          <textarea v-model="recipeForm.description" placeholder="请输入菜谱描述" class="textarea" placeholder-style="color: #999;"></textarea>
        </view>

        <!-- 分类选择 -->
        <view class="form-item">
          <text class="label">分类 *</text>
          <view class="category-selector">
            <scroll-view scroll-x class="category-scroll" show-scrollbar="false">
              <view class="category-items">
                <view class="category-item" v-for="category in categories" :key="category.id" 
                      :class="{active: recipeForm.category_id === category.id}" 
                      @click="selectCategory(category.id)">
                  <text>{{category.name}}</text>
                </view>
              </view>
            </scroll-view>
          </view>
        </view>

        <!-- 难度选择 -->
        <view class="form-item">
          <text class="label">难度 *</text>
          <view class="difficulty-selector">
            <view class="difficulty-item" v-for="level in difficulties" :key="level" 
                  :class="{active: recipeForm.difficulty === level}" 
                  @click="selectDifficulty(level)">
              <text>{{level}}</text>
            </view>
          </view>
        </view>

        <!-- 烹饪时间 -->
        <view class="form-item">
          <text class="label">烹饪时间 (分钟) *</text>
          <input type="number" v-model="recipeForm.cook_time" placeholder="请输入烹饪时间" class="input" placeholder-style="color: #999;" />
        </view>

        <!-- 份量 -->
        <view class="form-item">
          <text class="label">份量</text>
          <text class="hint-text">（填写数字，如2表示可供2人食用）</text>
          <input type="number" v-model="recipeForm.servings" placeholder="请输入份量" class="input" placeholder-style="color: #999;" />
        </view>
      </view>

      <!-- 食材添加 -->
      <view class="form-section">
        <view class="section-header">
          <text class="section-title">食材</text>
          <view class="add-btn" @click="addIngredient">
            <uni-icons type="plusempty" size="14" title="添加食材"/>
          </view>
        </view>
        <text class="hint-text">点击"+"添加食材，选择分类并填写名称、数量和单位</text>
        <view v-if="recipeForm.ingredients.length > 0" class="ingredients-list">
          <view class="ingredient-item" v-for="(ingredient, index) in recipeForm.ingredients" :key="index">
            <view class="ingredient-inputs">
              <view class="ingredient-row">
                  <view class="ingredient-categories">
                    <view class="category-tag" 
                          v-for="category in ingredientCategories" 
                          :key="category.id" 
                          :class="{active: ingredient.category_id === category.id}" 
                          @click="selectIngredientCategory(category.id, index)">
                      <text>{{category.name}}</text>
                    </view>
                  </view>
                </view>
                <view class="ingredient-row">
                  <input type="text" v-model="ingredient.name" placeholder="食材名称" class="ingredient-name-full" placeholder-style="color: #999;" />
                </view>
                <view class="ingredient-row">
                  <input type="number" v-model="ingredient.quantity" placeholder="数量" class="ingredient-quantity" placeholder-style="color: #999;" />
                  <picker mode="selector" :range="units" v-model="ingredient.unit_index" @change="onUnitChange($event, index)">
                    <view class="ingredient-unit">
                      {{ ingredient.unit || '选择单位' }}
                    </view>
                  </picker>
                </view>
              </view>
            <uni-icons type="trash" size="18" color="#999" @click="removeIngredient(index)" />
          </view>
        </view>
        <view v-else class="empty-tip">点击右上角+添加食材</view>
      </view>

      <!-- 步骤添加 -->
      <view class="form-section">
        <view class="section-header">
          <text class="section-title">步骤</text>
          <view class="add-btn" @click="addStep">
            <uni-icons type="plusempty" size="14" title="添加步骤"/>
          </view>
        </view>
        <text class="hint-text">点击"+"添加烹饪步骤，按实际操作顺序填写详细说明</text>
        <view v-if="recipeForm.steps.length > 0" class="steps-list">
          <view class="step-item" v-for="(step, index) in recipeForm.steps" :key="index">
            <view class="step-number">{{index + 1}}</view>
            <textarea v-model="step.description" placeholder="请输入步骤描述" class="step-textarea" placeholder-style="color: #999;"></textarea>
            <uni-icons type="trash" size="18" color="#999" @click="removeStep(index)" />
          </view>
        </view>
        <view v-else class="empty-tip">点击标题右侧的+号添加步骤</view>
      </view>

      <!-- 标签添加 -->
      <view class="form-section">
        <view class="section-header">
          <text class="section-title">标签</text>
        </view>
        <text class="hint-text">点击选择标签，可多选</text>
        <view class="tags-selector">
          <view v-if="availableTags.length > 0" class="tags-container">
            <view class="tag-item" v-for="tag in availableTags" :key="tag.id" 
                  :class="{active: isTagSelected(tag.id)}" 
                  @click="toggleTagSelection(tag.id)">
              <text>{{tag.name}}</text>
            </view>
          </view>
          <view v-else class="empty-tip">暂无数据</view>
        </view>
      </view>
    </view>
    
    <!-- 创建/更新按钮 -->
    <button class="create-button" @click="saveRecipe">
      {{ isEditMode ? '更新菜谱' : '创建菜谱' }}
    </button>
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { getAllCategories, getIngredientCategories, getAllTags } from '/apis/index.js';

const router = useRouter();

// 模式切换
const isEditMode = ref(false);
const recipeId = ref(null);

// 贴边按钮展开状态
const isActionsExpanded = ref(false);

// 从本地存储获取用户信息
defineExpose({
  getUserInfo
});

function getUserInfo() {
  try {
    const userInfo = uni.getStorageSync('userInfo');
    if (userInfo) {
      return JSON.parse(userInfo);
    }
  } catch (error) {
    console.error('获取用户信息失败', error);
  }
  return null;
}

// 切换贴边按钮展开/收起
const toggleActions = () => {
  isActionsExpanded.value = !isActionsExpanded.value;
}

// 菜谱表单数据
const recipeForm = ref({
  title: '',
  description: '',
  user_id: null, // 将从登录信息中获取
  category_id: null,
  difficulty: '简单',
  cook_time: '',
  servings: '',
  cover_image: '',
  ingredients: [],
  steps: [],
  tags: []
});

// 分类数据
const categories = ref([]);

// 加载菜谱分类
const loadCategories = async () => {
  try {
    const data = await getAllCategories();
    if (data && data.length > 0) {
      categories.value = data;
    }
  } catch (error) {
    console.error('加载分类失败', error);
    // 使用备用分类数据
    categories.value = [
      { id: 1, name: '中餐' },
      { id: 2, name: '西餐' },
      { id: 3, name: '甜点' },
      { id: 4, name: '主食' },
      { id: 5, name: '汤羹' },
      { id: 6, name: '小吃' }
    ];
  }
};

// 难度选项
const difficulties = ref(['简单', '中等', '困难']);

// 可用标签列表（后端预设标签）
const availableTags = ref([]);

// 已选中的标签ID集合
const selectedTagIds = ref(new Set());

// 加载标签列表（获取后端预设的标签）
const loadTags = async () => {
  try {
    const data = await getAllTags();
    if (data && data.length > 0) {
      availableTags.value = data;
    } else {
      // 没有获取到数据时，清空数组以便显示"暂无数据"
      availableTags.value = [];
    }
  } catch (error) {
    console.error('加载标签失败', error);
    // API调用失败时，清空数组以便显示"暂无数据"
    availableTags.value = [];
  }
};

// 检查标签是否被选中
const isTagSelected = (tagId) => {
  return selectedTagIds.value.has(tagId);
};

// 切换标签选中状态
const toggleTagSelection = (tagId) => {
  if (selectedTagIds.value.has(tagId)) {
    selectedTagIds.value.delete(tagId);
  } else {
    selectedTagIds.value.add(tagId);
  }
};

// 返回上一页
const back = () => {
  router.back();
};

// 切换到创建模式
const switchToCreate = () => {
  isEditMode.value = false;
  recipeId.value = null;
  // 重置表单
  resetForm();
};

// 切换到编辑模式
const switchToEdit = () => {
  isEditMode.value = true;
  // 用户自己实现编辑模式的JS逻辑
  // 此处仅保留模板结构，数据加载等逻辑用户后续自行实现
};

// 重置表单
const resetForm = () => {
  const userInfo = getUserInfo();
  recipeForm.value = {
    title: '',
    description: '',
    user_id: userInfo ? userInfo.id : null,
    category_id: null,
    difficulty: '简单',
    cook_time: '',
    servings: '',
    cover_image: '',
    ingredients: [],
    steps: [],
    tags: []
  };
  
  // 重置标签选择
  selectedTagIds.value = new Set();
};

// 初始化用户信息和分类数据
onMounted(() => {
  // 加载用户信息
  const userInfo = getUserInfo();
  if (userInfo && userInfo.id) {
    recipeForm.value.user_id = userInfo.id;
  } else {
    // 未登录状态提示
    uni.showToast({
      title: '请先登录',
      icon: 'none',
      duration: 2000
    });
  }
  
  // 加载分类数据和标签数据
  loadCategories();
  loadTags(); // 加载标签不影响用户自定义输入
});

// 选择分类
const selectCategory = (id) => {
  recipeForm.value.category_id = id;
};

// 选择难度
const selectDifficulty = (level) => {
  recipeForm.value.difficulty = level;
};

// 食材分类数据 
const ingredientCategories = ref([
  { id: 1, name: '肉类' },
  { id: 2, name: '蔬菜' },
  { id: 3, name: '调料' },
  { id: 4, name: '主食' },
  { id: 5, name: '其他' }
]);

// 加载食材分类 - 现在使用静态数据，此函数保留用于兼容性
const loadIngredientCategories = () => {
  // 已使用静态数据初始化，无需实际加载
  return Promise.resolve();
};

// 计量单位选项
const units = ref(['克', '毫升', '个', '根', '片', '勺', '碗', '份', '适量', '瓣']);

// 食材添加
const addIngredient = () => {
  // 查找默认分类的索引
  const defaultCategoryIndex = ingredientCategories.value.findIndex(cat => cat.id === 1);
  // 查找默认单位的索引
  const defaultUnitIndex = units.value.indexOf('克');
  
  recipeForm.value.ingredients.push({
    ingredient_id: null,
    name: '',
    category_id: 1, // 默认分类为"其他"
    category_index: defaultCategoryIndex >= 0 ? defaultCategoryIndex : 0,
    quantity: '',
    unit: '克', // 默认单位
    unit_index: defaultUnitIndex >= 0 ? defaultUnitIndex : 0
  });
};

// 食材分类选择
const selectIngredientCategory = (categoryId, index) => {
  recipeForm.value.ingredients[index].category_id = categoryId;
  // 查找对应的索引（如果需要保持兼容性）
  const categoryIndex = ingredientCategories.value.findIndex(cat => cat.id === categoryId);
  if (categoryIndex >= 0) {
    recipeForm.value.ingredients[index].category_index = categoryIndex;
  }
};

// 保持原有的分类选择变更函数以确保兼容性
const onCategoryChange = (e, index) => {
  const categoryIndex = e.detail.value;
  recipeForm.value.ingredients[index].category_index = categoryIndex;
  recipeForm.value.ingredients[index].category_id = ingredientCategories.value[categoryIndex].id;
};

// 食材单位选择变更
const onUnitChange = (e, index) => {
  const unitIndex = e.detail.value;
  recipeForm.value.ingredients[index].unit_index = unitIndex;
  recipeForm.value.ingredients[index].unit = units.value[unitIndex];
};

// 删除食材
const removeIngredient = (index) => {
  recipeForm.value.ingredients.splice(index, 1);
};

// 添加步骤
const addStep = () => {
  recipeForm.value.steps.push({ description: '', image_url: '' });
};

// 删除步骤
const removeStep = (index) => {
  recipeForm.value.steps.splice(index, 1);
};

// 转换标签数据格式以匹配API要求
const transformTagsForAPI = () => {
  // 从selectedTagIds集合中获取选中的标签ID，并转换为后端需要的格式
  return Array.from(selectedTagIds.value).map(tagId => {
    const tag = availableTags.value.find(t => t.id === tagId);
    return {
      tag_id: tagId,
      name: tag ? tag.name : ''
    };
  });
};

// 上传封面图片
const uploadCover = async () => {
  try {
    const [chooseRes] = await uni.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      sourceType: ['album', 'camera']
    });
    
    const tempFilePath = chooseRes.tempFilePaths[0];
    
    uni.showLoading({ title: '上传中...' });
    
    // 上传图片到服务器
    const [uploadRes] = await uni.uploadFile({
      url: 'http://localhost:5000/upload',
      filePath: tempFilePath,
      name: 'file',
      header: {
        'Authorization': `Bearer ${uni.getStorageSync('token')}`
      }
    });
    
    const data = JSON.parse(uploadRes.data);
    
    if (uploadRes.statusCode === 200) {
      recipeForm.value.cover_image = data.image_url; // 保存返回的图片URL
    } else {
      uni.showToast({ title: '上传失败', icon: 'none' });
    }
  } catch (error) {
    console.error('上传图片失败', error);
    uni.showToast({ title: '上传失败，请重试', icon: 'none' });
  } finally {
    uni.hideLoading();
  }
};

// 表单验证函数
const validateForm = () => {
  const { title, category_id, difficulty, cook_time, user_id } = recipeForm.value;
  
  // 验证必填字段
  if (!title || title.trim() === '') {
    uni.showToast({ title: '请输入菜谱标题', icon: 'none' });
    return false;
  }
  
  if (!category_id) {
    uni.showToast({ title: '请选择菜谱分类', icon: 'none' });
    return false;
  }
  
  if (!difficulty) {
    uni.showToast({ title: '请选择难度级别', icon: 'none' });
    return false;
  }
  
  if (!cook_time || isNaN(Number(cook_time)) || Number(cook_time) <= 0) {
    uni.showToast({ title: '请输入有效的烹饪时间', icon: 'none' });
    return false;
  }
  
  if (!user_id) {
    uni.showToast({ title: '用户信息错误，请重新登录', icon: 'none' });
    return false;
  }
  
  // 验证食材
  if (recipeForm.value.ingredients.length === 0) {
    uni.showToast({ title: '请至少添加一种食材', icon: 'none' });
    return false;
  }
  
  // 验证步骤
  if (recipeForm.value.steps.length === 0) {
    uni.showToast({ title: '请至少添加一个步骤', icon: 'none' });
    return false;
  }
  
  return true;
};

// 转换食材数据格式以匹配API要求
const transformIngredientsForAPI = (ingredients) => {
  return ingredients.map(ing => ({
    ingredient_id: ing.ingredient_id || null,
    name: ing.name,
    category_id: ing.category_id,
    quantity: ing.quantity,
    unit: ing.unit
  }));
};



// 保存菜谱
const saveRecipe = async () => {
  // 基本表单验证
  if (!validateForm()) {
    return;
  }
  
  try {
    uni.showLoading({ title: '提交中...' });
    
    // 转换食材和标签数据格式
    const formattedRecipe = {
      ...recipeForm.value,
      ingredients: transformIngredientsForAPI(recipeForm.value.ingredients),
      tags: transformTagsForAPI()
    };
    
    // 输出提交内容以便调试
    console.log('提交的菜谱内容:', formattedRecipe);

    if (isEditMode.value) {
      console.log('更新菜谱', formattedRecipe);
      // 用户自己实现更新API调用
    } else {
      // 实际API调用
      const res = await uni.request({
        url: 'http://localhost:5000/recipes',
        method: 'POST',
        data: formattedRecipe,
        header: {
          'Content-Type': 'application/json',
          'Authorization': `Bearer ${uni.getStorageSync('token')}`
        }
      });
      
      if (res.statusCode === 201) {
        uni.showToast({ title: '创建成功' });
        // 成功后返回上一页
        setTimeout(() => {
          router.back();
        }, 1500);
      } else if (res.data && res.data.message) {
        uni.showToast({
          title: res.data.message,
          icon: 'none'
        });
      } else {
        // 后端要求食材和标签必须已存在于数据库中
        // 如果用户输入的标签或食材不存在，这里会显示错误
        // 注意：根据后端API要求，食材必须使用已存在的食材ID
        uni.showToast({
          title: '创建失败，请检查食材和标签是否存在',
          icon: 'none'
        });
      }
    }
  } catch (error) {
    console.error('创建菜谱失败', error);
    uni.showToast({ title: '网络错误，请重试', icon: 'none' });
  } finally {
    uni.hideLoading();
  }
};
</script>

<style lang="scss" scoped>
.creation-page {
  min-height: 100vh;
  background-color: #f8f8f8;
}

// 贴边操作按钮样式
// 贴边操作按钮容器
.side-action-wrapper {
  position: fixed;
  right: 0;
  top: 50%;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

// 触发按钮 - 更宽更短的长方形
.trigger-button {
  width: 15px;
  height: 100px;
  background-color: #ff6b6b;
  border-radius: 30px 0 0 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: background-color 0.3s;
  position: relative;
  z-index: -1;
}

.trigger-button:active {
  background-color: #ff5826;
}

.trigger-text {
  color: #fff;
  font-size: 14px;
  font-weight: 500;
}

// 操作按钮组容器
.actions-container {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  position: absolute;
  right: 0;
  bottom: -250%;
  transform: translateX(100%);
  transition: transform 0.3s ease-out;
  z-index: 1;
}

// 展开时的动画效果
.actions-container.expanded {
  transform: translateX(0);
}

// 操作按钮样式 - 从右往左滑出
.action-button {
  width: 160px;
  height: 48px;
  border-radius: 4px 0 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: all 0.3s ease;
  margin-bottom: 12px;
  opacity: 0;
  transform: translateX(100%);
}

// 展开时按钮依次显示的动画
.actions-container.expanded .action-button {
  opacity: 1;
  transform: translateX(0);
}

// 按钮动画延迟，创建按钮先显示
.actions-container.expanded .create {
  transition-delay: 0.1s;
}

// 编辑按钮稍晚显示
.actions-container.expanded .edit {
  transition-delay: 0.2s;
}

.action-button:active {
  opacity: 0.8;
}

.action-text {
  color: #fff;
  font-size: 14px;
  margin-left: 6px;
}

// 创建按钮样式
.action-button.create {
  background-color: #52c41a;
}

// 编辑按钮样式
.action-button.edit {
  background-color: #faad14;
}

// 防止点击菜单外部时菜单关闭
.content-container {
  position: relative;
  z-index: 1;
}

// 内容容器
.content-container {
  padding: 20px;
}

// 封面图片上传
.cover-upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 30px;
}

.cover-image {
  width: 200px;
  height: 200px;
  border-radius: 12px;
  background-color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.upload-tip {
  margin-top: 10px;
  font-size: 14px;
  color: #999;
}

// 表单区域
.form-section {
  background-color: #fff;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.form-item {
  margin-bottom: 20px;
}

.form-item:last-child {
  margin-bottom: 0;
}

.label {
  display: block;
  font-size: 14px;
  color: #333;
  margin-bottom: 8px;
}

.input {
  width: 100%;
  height: 44px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 0 12px;
  font-size: 14px;
  color: #333;
  box-sizing: border-box;
}

.textarea {
  width: 100%;
  height: 100px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  color: #333;
  box-sizing: border-box;
  resize: none;
}

// 提示文本样式
.hint-text {
  display: block;
  font-size: 12px;
  color: #999;
  margin: -4px 0 8px 0;
}

// 添加按钮样式
.add-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s;
  cursor: pointer;

  &:active {
    background-color: #ff6b6b; /* 点击时颜色稍深 */
    transform: scale(0.95);
  }
}

// 分类选择器
.category-selector {
  margin-top: 8px;
}

.category-scroll {
  width: 100%;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  // 隐藏滚动条 - 兼容各主流浏览器
  -ms-overflow-style: none;  // IE和Edge
  scrollbar-width: none;     // Firefox
}

// Chrome、Safari和Opera
.category-scroll::-webkit-scrollbar {
  display: none;
}

.category-items {
  display: inline-flex;
  gap: 20rpx;
  padding: 12rpx 0;
}

.category-item {
    padding: 16rpx 28rpx;
    background-color: #f8f8f8;
    border-radius: 28rpx;
    font-size: 28rpx;
    color: #666;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

.category-item.active {
  background-color: #ff6b6b;
  color: #fff;
}

// 难度选择器
.difficulty-selector {
  display: flex;
  gap: 20rpx;
  margin-top: 24rpx;
}

.difficulty-item {
  flex: 1;
  padding: 20rpx 16rpx;
  background-color: #f8f8f8;
  border-radius: 16rpx;
  text-align: center;
  font-size: 28rpx;
  color: #666;
  transition: all 0.3s;
}

.difficulty-item.active {
  background-color: #ff6b6b;
  color: #fff;
}

// 区域头部
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28rpx;
}

.section-title {
  font-size: 36rpx;
  font-weight: 600;
  color: #333;
}

// 食材列表
.ingredients-list {
  .ingredient-item {
    display: flex;
    align-items: center;
    margin-bottom: 24rpx;
    background-color: #fafafa;
    padding: 20rpx;
    border-radius: 16rpx;
  }
  
  .ingredient-item:last-child {
    margin-bottom: 0;
  }
  
  .ingredient-inputs {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16rpx;
    width: 100%;
  }
  
  .ingredient-row {
    display: flex;
    gap: 16rpx;
    width: 100%;
  }
  
  .ingredient-unit {
    flex: 1;
    height: 68rpx;
    border: 1rpx solid #e0e0e0;
    border-radius: 10rpx;
    padding: 0 20rpx;
    font-size: 28rpx;
    background-color: #fff;
    display: flex;
    align-items: center;
  }
  
  .ingredient-name {
    flex: 2;
    height: 68rpx;
    border: 1rpx solid #e0e0e0;
    border-radius: 10rpx;
    padding: 0 20rpx;
    font-size: 28rpx;
  }
  
  .ingredient-name-full {
    width: 100%;
    height: 68rpx;
    border: 1rpx solid #e0e0e0;
    border-radius: 10rpx;
    padding: 0 20rpx;
    font-size: 28rpx;
  }
  
  .ingredient-quantity {
    flex: 1;
    height: 68rpx;
    border: 1rpx solid #e0e0e0;
    border-radius: 10rpx;
    padding: 0 20rpx;
    font-size: 28rpx;
  }
  
  // 食材分类标签选择样式 - 与难度选择器样式保持一致
  .ingredient-categories {
    display: flex;
    gap: 20rpx;
    margin-top: 24rpx;
  }
  
  .category-tag {
    flex: 1;
    padding: 20rpx 16rpx;
    background-color: #f8f8f8;
    border-radius: 16rpx;
    text-align: center;
    font-size: 28rpx;
    color: #666;
    transition: all 0.3s;
  }
  
  .category-tag.active {
    background-color: #ff6b6b;
    color: #fff;
  }
}

// 步骤列表
.steps-list {
  .step-item {
    display: flex;
    margin-bottom: 28rpx;
    align-items: flex-start;
  }
  
  .step-number {
    width: 48rpx;
    height: 48rpx;
    background-color: #ff6b6b;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28rpx;
    font-weight: bold;
    margin-right: 20rpx;
    flex-shrink: 0;
  }
  
  .step-textarea {
    flex: 1;
    height: 140rpx;
    border: 1rpx solid #e0e0e0;
    border-radius: 12rpx;
    padding: 20rpx 24rpx;
    font-size: 28rpx;
    resize: none;
  }
}

// 标签选择器
.tags-selector {
  margin-top: 2rpx;
  width: 100%;
}

.tags-container {
  display: flex;
  justify-content: left;
  align-items: center;
  flex-wrap: wrap;
  gap: 20rpx;
  width: 100%;
  box-sizing: border-box;
}

.tag-item {
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 calc(22% - 15rpx);
  padding: 20rpx 16rpx;
  background-color: #f8f8f8;
  border-radius: 16rpx;
  font-size: 28rpx;
  color: #666;
  transition: all 0.3s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-sizing: border-box;
}

.tag-item.active {
  background-color: #ff6b6b;
  color: #fff;
}



// 空提示
.empty-tip {
  text-align: center;
  color: #999;
  font-size: 28rpx;
  padding: 48rpx 0;
}

// 创建/更新按钮 - 极简设计
.create-button {
  width: calc(100% - 96rpx);
  height: 88rpx;
  background-color: #ff6b6b;
  color: #fff;
  border: none;
  border-radius: 44rpx;
  font-size: 36rpx;
  font-weight: 500;
  transition: all 0.2s ease;
  outline: none;
  cursor: pointer;
  margin: 48rpx 48rpx 72rpx 48rpx;
}

// 简化按钮交互效果
.create-button:active {
  background-color: #ff5252;
}
</style>
